<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<script>
    const arr = [1, 2, 3, 4, 5]

    // find 会返回符合条件的值  如果有多个符合，只返回 第一个符合的值
    const my = arr.find((value, index, arr) => { // 当前值，索引，数组对象
        return index == 3
    })
    console.log(my)

    // findIndex 和 find 几乎一样，只是findIndex返回符合值的索引下标
    const arr1 = [1, 2, 3, 4, 5]
    const my1 = arr.findIndex((value, index, arr) => {
        return value == 3
    })
    console.log(my1)


    // for in 可以遍历对象，数组   key 是索引
    // for of 只能遍历 数组    key 是当前值

    // 区别  for of 不能遍历对象
    const obj = {
        name: 'nick',
        age: 21,
        email: '123'
    }

    for (let key in obj) {
        console.log(key, obj[key])
    }

    // for (let key of obj) {
    //     console.log(key)
    // }
    const myArr = [{
        name: 'jack'
    }, {
        name: 'marry'
    }]

    for (let key in myArr) {
        console.log(key, myArr[key])
    }

    for (let key of myArr) {
        console.log(myArr)
    }
    // 快速设置数组中所有对象的值为undefined
    let obj_my = {
        name: '1234',
        age: 21,
        email: '134214',
        address: '张三李四',
        zaa: '432141'
    }
    for (let key in obj_my) {
        obj_my[key] = undefined
    }
    console.log(obj_my)
</script>
</body>

</html>
